using System.Collections;
using System.IO;
using System;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Grid;
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
using DevExpress.Utils;
//using System.Data.OleDb.OleDbCommandBuilder;//JMR -- DEV -- commented out
using System.Data.OleDb;//JMR -- DEV -- added
//using System.Data.Common.DbCommandBuilder;//JMR -- DEV -- commented out
using System.Data.Common;//JMR -- DEV -- added
//using System.Object;//JMR -- DEV -- commented out
//using System;//JMR -- DEV -- added
//using System.MarshalByRefObject;//JMR -- DEV -- commented out
//using System.ComponentModel.Component;//JMR -- DEV -- commented out
//using System.ComponentModel;//JMR -- DEV -- added
//using System.Data.OleDb;
using DevExpress.XtraReports.UI;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using DevExpress.XtraTab;
using DevExpress.XtraTab.ViewInfo;
namespace ePlanSysOman
{
    public partial class frmAssemply
    {
        private string OldHarnessPTP = "";
          // ERROR: Handles clauses are not supported in C#

        #region frmAssemply_Load
    private void frmAssemply_Load(object sender, System.EventArgs e)
        {
            DataSet aset = new DataSet();
            clsData data2 = new clsData();
            clsData data = new clsData();
            if (!Module1.newModule.BAckhrn)
            {
                aset = data2.getData("select DISTINCT DWG,DASH from MPRS ");
                if ((aset.Tables[0].Rows.Count == 0))
                {
                    XtraMessageBox.Show("No Assemply  data found in database!");
                    this.Close();
                }
                else
                {
                    this.grdHarnSel.DataSource = aset.Tables[0];
                    this.grdHarnSel.Refresh();
                    Module1.newModule.oldSel = false;
                }
            }
        }
        #endregion
        private void grdHarnSel_DoubleClick(object sender, System.EventArgs e) // ERROR: Handles clauses are not supported in C#
        {
            DataSet aset = new DataSet();
            clsData data = new clsData();
            this.OldHarnessPTP = Conversions.ToString(this.viewHarnSel.GetRowCellValue(this.viewHarnSel.GetSelectedRows()[0], "DWG"));//JMR
            Module1.newModule.OldDRW = Conversions.ToString(this.viewHarnSel.GetRowCellValue(this.viewHarnSel.GetSelectedRows()[0], "DASH"));//JMR
            txtOldHarnessPTP.Text = this.OldHarnessPTP;
            if ((XtraMessageBox.Show(("You select parts from " + this.OldHarnessPTP + " to be added on card? "), "Confirm selection", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes))
            {
                clsData data2 = new clsData();
                Application.DoEvents();
                data.ExecuteSQL("UPDATE MPRS SET DWG_ZONE ='-' WHERE DWG_ZONE IS NULL ");
                if (!Module1.newModule.BAckhrn)
                {
                    try
                    {
                        this.pr1.Properties.Maximum = 100;
                        this.pr1.EditValue = 0x23;
                        this.pr1.Update();
                        Cursor.Current = Cursors.WaitCursor;
                        aset = data.getData(string.Concat(new string[] {
              " SELECT * FROM  MPRS WHERE  DWG = '",
              this.OldHarnessPTP,
              "' AND  DASH ='",
              Module1.newModule.OldDRW,
              "'"
            }));
                        this.pr1.EditValue = 100;
                        this.pr1.Update();
                    }
                    catch (Exception exception1)
                    {
                        ProjectData.SetProjectError(exception1);
                        Exception exception = exception1;
                        //   XtraMessageBox.Show(exception.Message)
                        ProjectData.ClearProjectError();
                    }
                    int num4 = (aset.Tables[0].Rows.Count - 1);
                    int i = 0;
                    while ((i <= num4))
                    {
                        this.pr1.Properties.Minimum = 1;
                        this.pr1.Properties.Maximum = aset.Tables[0].Rows.Count;
                        this.pr1.EditValue = (i + 1);
                        this.pr1.Update();
                        DataRow row = aset.Tables[0].Rows[i];
                        string str4 = Conversions.ToString(row[4]);
                        string str5 = Conversions.ToString(row[5]);
                        string str3 = Conversions.ToString(Interaction.IIf((object.ReferenceEquals(row[11], DBNull.Value)), "-", RuntimeHelpers.GetObjectValue(row[11])));
                        string str2 = Conversions.ToString(row[9]);
                        string str8 = Conversions.ToString(row[12]);
                        string str7 = Conversions.ToString(row[6]);
                        int num2 = Conversions.ToInteger(row[7]);
                        int num3 = Conversions.ToInteger(row[8]);
                        string str6 = Conversions.ToString(row[1]);
                        switch (str2)
                        {
                            case "D":
                                str2 = "DELETE";
                                break; // TODO: might not be correct. Was : Exit Select

                            case "A":
                                str2 = "ADD";
                                break; // TODO: might not be correct. Was : Exit Select

                            case "R":
                                str2 = "REWORK";
                                break; // TODO: might not be correct. Was : Exit Select

                        }
                        string sQL = "INSERT INTO tblAssembly";
                        string word = Module1.newModule.OldDRW;//JMR
                        sQL = (sQL + "(prtPlid,prtDash,prtQty,prtPartNumberDoc,prtDescription,prtEcp,prtFlag,prtAction,prtDwgZone,prtTypeVer,prtFrom,prtThru) VALUES");
                        sQL = string.Concat(new string[] {
              sQL,
              "('",
              Module1.newModule.assPlanNumber,
              "','" + word + "','",//JMR
              str5,
              "','",
              str4,
              "','",
              str3,
              "','",
              OldHarnessPTP,
              "','','",
              str2,
              "','",
              str8,
              "','",
              str7,
              "',",
              Conversions.ToString(num2),
              ",",
              Conversions.ToString(num3),
              ")"
            });
                        data.ExecuteSQL(sQL);
                        row = null;
                        i += 1;
                    }
                    this.txtOldHarnessPTP.Text = "";
                    Module1.newModule.oldSel = false;
                }
                this.Close();
            }
            else
            {
                this.txtOldHarnessPTP.Text = "";
                Module1.newModule.oldSel = false;
            }
        }

        public frmAssemply()
        {
            InitializeComponent(); 
        }
    }
}

